package cn.tedu.mall.seckill.controller;

import cn.tedu.mall.common.restful.JsonPage;
import cn.tedu.mall.common.restful.JsonResult;
import cn.tedu.mall.pojo.seckill.vo.SeckillSpuVO;
import cn.tedu.mall.seckill.service.ISeckillSpuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class SeckillSpuController {

    @Autowired
    private ISeckillSpuService seckillSpuService;

    @GetMapping("/seckill/spu/list")
    @PreAuthorize("permitAll()")
    public JsonResult<JsonPage<SeckillSpuVO>> listSeckillSpus(){
        JsonPage<SeckillSpuVO> jsonPage = seckillSpuService.listSeckillSpus(null, null);
        return JsonResult.ok(jsonPage);
    }


    @GetMapping("/seckill/spu/{spuId}")
    @PreAuthorize("permitAll()")
    public JsonResult<SeckillSpuVO> getSeckillSpu(@PathVariable("spuId") Long spuId){
        SeckillSpuVO seckillSpu = seckillSpuService.getSeckillSpu(spuId);
        return JsonResult.ok(seckillSpu);
    }
}
